<?php
/**
 * ZView
 *
 * Zend Frameworks View Component for TYPO3
 *
 * @package    ZView
 * @copyright  Copyright (c) Zephir AG, www.zephir.ch
 */

/** Abstract class for extension */
require_once 'Zend/View/Helper/Abstract.php';

/**
 * Helper to generate an "url" (using for the href attribute)
 *
 * @package ZView
 * @copyright  Copyright (c) Zephir AG, www.zephir.ch
 */
class Tx_Zview_Helper_T3flexform extends Zend_View_Helper_Abstract
{

	/**
	 * Retrieve a flexform value
	 *
	 * Return a value from somewhere inside a FlexForm structure. This is a simple
	 * wrapper for tslib_pibase::pi_getFFvalue().
	 *
	 * @param	string		Field name to extract. Can be given like "test/el/2/test/el/field_templateObject" where each part will dig a level deeper in the FlexForm data.
	 * @param	string		Sheet pointer, eg. "sDEF"
	 * @param	string		Language pointer, eg. "lDEF"
	 * @param	string		Value pointer, eg. "vDEF"
	 * @return	string		The content.
	 */
	public function t3flexform($fieldName,$sheet='sDEF',$lang='lDEF',$value='vDEF')
	{
		$pi = $this->view->getPi();
		if(empty($pi) || (!$pi instanceof tslib_pibase)) {
			throw new Exception('Please set tslib_pibase using $view->setPi($this) in your plugin class.');
		}
		$T3FlexForm_array = $pi->cObj->data['pi_flexform'];
		return $pi->pi_getFFvalue($T3FlexForm_array, $fieldName, $sheet, $lang, $value);
	}

}

if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/zview/helper/T3flexform.php']) {
	include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/zview/helper/T3flexform.php']);
}
